import React, { useCallback, useEffect, useState } from 'react';
import useBasisCash from './useBasisCash';
import config from '../config';

const useStakeCards = (color:number):any => {
  const [stat, setStat] = useState([]);
  const basisCash = useBasisCash();

  const fetchLiquidityOracle = useCallback(async () => {
      const stat = await basisCash.getMyStake(color);
      setStat(stat);
  }, [basisCash]);

  useEffect(() => {
    fetchLiquidityOracle().catch((err) => console.error(`Failed to fetch useStakeCards: useStakeCards ${err.stack}`));
    const refreshInterval = setInterval(fetchLiquidityOracle, config.refreshInterval);
    return () => clearInterval(refreshInterval);
  }, [basisCash]);

  return stat;
};

export default useStakeCards;
